#!/bin/sh

# Usage: defrag device cvfname
# Examle: defrag /dev/hda1 dblspace.000

if [ $# != 2 ]; then
  echo "Usage: defrag device cvfname"
  echo "Example: defrag /dev/hda1 dblspace.000"
  exit 1
fi

mkdir /tmp/mountpoint
if ! mount -t dmsdos -o nofix $1 /tmp/mountpoint ; then
  rmdir /tmp/mountpoint
  exit 1
fi
ddefrag /tmp/mountpoint/$2
umount /tmp/mountpoint
rmdir /tmp/mountpoint
